package com.hyt.it.ogt.kq.common.gov.config.arrange;

import com.hyt.progress.creator.anno.ProgressAnno;
import com.hyt.progress.creator.policy.ProgressLockKeyCreator;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;

import java.util.Objects;

/**
 * 编排锁，参数中必须要有taskId
 **/
@Slf4j
public class CommonLockKeyCreator implements ProgressLockKeyCreator {
    public static final String PARAM_VALUE = "taskId";
    @Override
    public String createLockKey(ProceedingJoinPoint pjp, ProgressAnno progressAnno) {
        Object examId = getBodyParamValue(pjp, PARAM_VALUE);
        if (Objects.isNull(examId)) {
            examId = getQueryParamValue(pjp, PARAM_VALUE);
        }
        if (Objects.isNull(examId)) {
            throw new IllegalArgumentException("请传递taskId参数");
        }
        String className = getClassName(pjp);
        String methodName = getMethodName(pjp);
        return className + methodName + examId;
    }
}
